package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherControllerApi;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author 黄子弟
 */
@Slf4j
@RestController
public class CourseTeacherController implements CourseTeacherControllerApi {

    @Autowired
    private CourseTeacherService  courseTeacherService;

    @Override
    @GetMapping("/courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> queryCourseTeacherList(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        List<CourseTeacherDTO> dtos = courseTeacherService.queryCourseTeacherList(courseBaseId, companyId);
        return dtos;
    }

    @Override
    @PostMapping("courseTeacher")
    public CourseTeacherDTO createOrModifyCourseTeacher(@RequestBody CourseTeacherVO courseTeacherVO) {
        Long companyId = SecurityUtil.getCompanyId();
        CourseTeacherDTO courseTeacherDTO = CourseTeacherConvert.INSTANCE.vo2dto(courseTeacherVO);
        CourseTeacherDTO dto = courseTeacherService.createOrModifyCourseTeacher(courseTeacherDTO, companyId);
        return dto;
    }

    @Override
    @DeleteMapping("/courseTeacher/course/{courseId}/{courseTeacherId}")
    public void deleteCourseTeacher(@PathVariable("courseId") Long courseId,@PathVariable("courseTeacherId") Long courseTeacherId) {
        Long companyId = SecurityUtil.getCompanyId();
        courseTeacherService.deleteCourseTeacher(courseId, courseTeacherId, companyId);
    }
}
